package cn.com.taiji.pos.service.impl;

import cn.com.taiji.pos.entity.CardAccount;
import cn.com.taiji.pos.entity.CardAccountType;
import cn.com.taiji.pos.mapper.CardAccountMapper;
import cn.com.taiji.pos.mapper.CardAccountTypeMapper;
import cn.com.taiji.pos.service.ICardAccountService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 账户信息 服务实现类
 * </p>
 *
 * @author
 * @since 2021-03-01
 */
@Service
public class CardAccountServiceImpl extends ServiceImpl<CardAccountMapper, CardAccount> implements ICardAccountService {
    @Autowired
    private CardAccountMapper cardAccountMapper;
    @Autowired
    private CardAccountTypeMapper cardAccountTypeMapper;

    @Override
    public List<CardAccount> findCardAccountList(String customerId, String canci) {
        return cardAccountMapper.findCardAccountList(customerId, canci);
    }

    @Override
    public List<CardAccount> findCardAccountList(String customerId) {
        return cardAccountMapper.findCardAccountList2(customerId);

    }

    @Override
    public List<CardAccount> findCardAccountList2(String customerId) {
        return cardAccountMapper.findCardAccountList3(customerId);

    }

    @Override
    public CardAccount findCardAccount(String customerId, String accountCategoryId) {
        QueryWrapper<CardAccountType> cardAccountTypeWrapper = new QueryWrapper<>();
        cardAccountTypeWrapper.eq("ACCOUNT_CATEGORY_ID", accountCategoryId).eq("STATUS", 0);
        CardAccountType cardAccountType = cardAccountTypeMapper.selectOne(cardAccountTypeWrapper);
        if (cardAccountType != null) {
            QueryWrapper<CardAccount> cardAccountWrapper = new QueryWrapper<>();
            cardAccountWrapper.eq("CUSTOMER_ID", customerId).eq("ACCOUNT_TYPE_ID", cardAccountType.getId());
            return cardAccountMapper.selectOne(cardAccountWrapper);
        } else {
            return null;
        }
    }

    @Override
    public CardAccount findCardAccount(String customerId, String accountCategoryId, String mealTimeId) {
        QueryWrapper<CardAccountType> cardAccountTypeWrapper = new QueryWrapper<>();
        cardAccountTypeWrapper.eq("ACCOUNT_CATEGORY_ID", accountCategoryId).eq("STATUS", 0);
        CardAccountType cardAccountType = cardAccountTypeMapper.selectOne(cardAccountTypeWrapper);
        if (cardAccountType != null) {
            QueryWrapper<CardAccount> cardAccountWrapper = new QueryWrapper<>();
            cardAccountWrapper.eq("CUSTOMER_ID", customerId).eq("ACCOUNT_TYPE_ID", cardAccountType.getId()).eq("MEAL_TIME_ID", mealTimeId);
            return cardAccountMapper.selectOne(cardAccountWrapper);
        } else {
            return null;
        }
    }

    @Override
    public List<CardAccount> findByCustomerId(String customerId) {
        QueryWrapper<CardAccount> cardAccountWrapper = new QueryWrapper<>();
        cardAccountWrapper.eq("CUSTOMER_ID", customerId).eq("STATUS", 0);
        return cardAccountMapper.selectList(cardAccountWrapper);

    }
}
